package ltd.newbee.cloud.web;


import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.reactive.function.client.WebClient;
import reactor.core.publisher.Mono;

/**
 * @Auther: tangyushan
 * @Date: 2024/5/17 - 05 - 17 - 18:09
 * @Description: ltd.newbee.cloud.web
 * @version: 1.0
 */
@RestController
public class ConsumerController {

    private final String SERVICE_URL = "http://localhost:8081";
//    private final String SERVICE_URL = "http://localhost:8082";

    private WebClient webClient = WebClient.builder()
            .baseUrl(SERVICE_URL)
            .build();

    @GetMapping("/webClientTest")
    public String webClientTest(){
        Mono<String> mono = webClient.get()
                .uri("/hello")
                .retrieve()
                .bodyToMono(String.class);
        mono.subscribe(result->{
            System.out.println(result);
        });

        return "请求成功4";
    }
}
